home *** CD-ROM | disk | FTP | other *** search
/ Aminet 6 / Aminet 6 - June 1995.iso / Aminet / gfx / 3d / irit50src.lha / irit5 / grapdrvs / xogldraw.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-22  |  22.9 KB  |  667 lines

  1. /*****************************************************************************
  2. *   An SGI 4D driver using Open GL.                         *
  3. *                                         *
  4. * Written by:  Gershon Elber                 Ver 0.1, October 1994.  *
  5. *****************************************************************************/
  6.  
  7. #ifdef __hpux
  8. typedef char *caddr_t;           /* Awful kludge. Let me know of a better way. */
  9. #endif /* __hpux */
  10.  
  11. #include <X11/Xlib.h>
  12. #include <X11/Xutil.h>
  13. #include <X11/cursorfont.h>
  14. #include <X11/Xresource.h>
  15.  
  16. #include <GL/glx.h>
  17. #include <GL/gl.h>
  18. #include <gl/glws.h>  
  19. #include <unistd.h>
  20.  
  21. #include <math.h>
  22. #include "irit_sm.h"
  23. #include "genmat.h"
  24. #include "iritprsr.h"
  25. #include "allocate.h"
  26. #include "attribut.h"
  27. #include "iritgrap.h"
  28. #include "x11drvs.h"
  29.  
  30. typedef enum {
  31.     GLXcolorIndexSingleBuffer,
  32.     GLXcolorIndexDoubleBuffer,
  33.     GLXrgbSingleBuffer,
  34.     GLXrgbDoubleBuffer
  35. } GLXWindowType;
  36.  
  37. static Colormap CMap;
  38.  
  39. static short Colors[IG_MAX_COLOR + 1][3] =
  40. {
  41.     { 0,   0,   0   },  /* 0. BLACK */
  42.     { 0,   0,   170 },  /* 1. BLUE */
  43.     { 0,   170, 0   },  /* 2. GREEN */
  44.     { 0,   170, 170 },  /* 3. CYAN */
  45.     { 170, 0,   0   },  /* 4. RED */
  46.     { 170, 0,   170 },  /* 5. MAGENTA */
  47.     { 170, 170, 0   },  /* 6. BROWN */
  48.     { 170, 170, 170 },  /* 7. LIGHTGREY */
  49.     { 85,  85,  85  },  /* 8. DARKGRAY */
  50.     { 85,  85,  255 },  /* 9. LIGHTBLUE */
  51.     { 85,  255, 85  },  /* 10. LIGHTGREEN */
  52.     { 85,  255, 255 },  /* 11. LIGHTCYAN */
  53.     { 255, 85,  85  },  /* 12. LIGHTRED */
  54.     { 255, 85,  255 },  /* 13. LIGHTMAGENTA */
  55.     { 255, 255, 85  },  /* 14. YELLOW */
  56.     { 255, 255, 255 }   /* 15. WHITE */
  57. };
  58.  
  59. static void SetColorRGB(int Color[3]);
  60. static void SetColorIndex(int c);
  61. static void SetEntry(GLXconfig* ptr, int b, int m, int a);
  62. static Window GLXCreateWindow(Display *XDisplay,
  63.                   Window Parent,
  64.                   int x,
  65.                   int y,
  66.                   int w,
  67.                   int h,
  68.                   int BorderWidth,
  69.                   GLXWindowType Type);
  70.  
  71. /*****************************************************************************
  72. * DESCRIPTION:                                                               M
  73. * Draw a single Point/Vector object using current modes and transformations. M
  74. *                                                                            *
  75. * PARAMETERS:                                                                M
  76. *   PObj:     A point/vector object to draw.                                 M
  77. *                                                                            *
  78. * RETURN VALUE:                                                              M
  79. *   void                                                                     M
  80. *                                                                            *
  81. * KEYWORDS:                                                                  M
  82. *   IGDrawPtVec                                                              M
  83. *****************************************************************************/
  84. void IGDrawPtVec(IPObjectStruct *PObj)
  85. {
  86.     int i;
  87.     PointType Ends[6], Zero;
  88.     RealType
  89.     *Pt = PObj -> U.Pt;
  90.  
  91.     for (i = 0; i < 6; i++)
  92.     PT_COPY(Ends[i], Pt);
  93.  
  94.     Ends[0][0] -= IG_POINT_WIDTH;
  95.     Ends[1][0] += IG_POINT_WIDTH;
  96.     Ends[2][1] -= IG_POINT_WIDTH;
  97.     Ends[3][1] += IG_POINT_WIDTH;
  98.     Ends[4][2] -= IG_POINT_WIDTH;
  99.     Ends[5][2] += IG_POINT_WIDTH;
  100.  
  101.     for (i = 0; i < 6; i += 2) {
  102.     glBegin(GL_LINES);
  103.     glVertex3dv(Ends[i]);
  104.     glVertex3dv(Ends[i+1]);
  105.     glEnd();
  106.     }
  107.  
  108.     if (IP_IS_VEC_OBJ(PObj)) {
  109.     glBegin(GL_LINES);
  110.     glVertex3dv(Pt);
  111.     Zero[0] = Zero[1] = Zero[2] = 0.0;
  112.     glVertex3dv(Zero);
  113.     glEnd();
  114.     }
  115. }
  116.  
  117. /*****************************************************************************
  118. * DESCRIPTION:                                                               M
  119. * Draw a single Poly object using current modes and transformations.         M
  120. *                                                                            *
  121. * PARAMETERS:                                                                M
  122. *   PObj:     A poly object to draw.                                         M
  123. *                                                                            *
  124. * RETURN VALUE:                                                              M
  125. *   void                                                                     M
  126. *                                                                            *
  127. * KEYWORDS:                                                                  M
  128. *   IGDrawPoly                                                               M
  129. *****************************************************************************/
  130. void IGDrawPoly(IPObjectStruct *PObj)
  131. {
  132.     IPVertexStruct *V;
  133.     IPPolygonStruct
  134.     *Pl = PObj -> U.Pl;
  135.  
  136.     if (IP_IS_POLYLINE_OBJ(PObj)) {
  137.     for (; Pl != NULL; Pl = Pl -> Pnext) {
  138.         glBegin(GL_LINE_STRIP);
  139.         for (V = Pl -> PVertex; V != NULL; V = V -> Pnext)
  140.             glVertex3dv(V -> Coord);
  141.         glEnd();
  142.     }
  143.     }
  144.     else if (IP_IS_POINTLIST_OBJ(PObj)) {
  145.     for (; Pl != NULL; Pl = Pl -> Pnext) {
  146.         for (V = Pl -> PVertex; V != NULL; V = V -> Pnext) {
  147.         int i;
  148.         PointType Ends[6];
  149.         RealType
  150.             *Pt = V -> Coord;
  151.  
  152.         for (i = 0; i < 6; i++)
  153.             PT_COPY(Ends[i], Pt);
  154.  
  155.         Ends[0][0] -= IG_POINT_WIDTH;
  156.         Ends[1][0] += IG_POINT_WIDTH;
  157.         Ends[2][1] -= IG_POINT_WIDTH;
  158.         Ends[3][1] += IG_POINT_WIDTH;
  159.         Ends[4][2] -= IG_POINT_WIDTH;
  160.         Ends[5][2] += IG_POINT_WIDTH;
  161.  
  162.         for (i = 0; i < 6; i += 2) {
  163.             glBegin(GL_LINES);
  164.             glVertex3dv(Ends[i]);
  165.             glVertex3dv(Ends[i+1]);
  166.             glEnd();
  167.         }
  168.         }
  169.     }
  170.     }
  171.     else if (IP_IS_POLYGON_OBJ(PObj)) {
  172.     int i, j,
  173.         NumOfVertices;
  174.     PointType PNormal, VNormal;
  175.  
  176.     for (; Pl != NULL; Pl = Pl -> Pnext) {
  177.         if (IGGlblDrawPNormal) {
  178.         NumOfVertices = 0;
  179.         PNormal[0] = PNormal[1] = PNormal[2] = 0.0;
  180.         }
  181.  
  182.         if (IGGlblDrawSolid) {
  183.         glBegin(GL_POLYGON);
  184.         for (V = Pl -> PVertex; V != NULL; V = V -> Pnext) {
  185.             glNormal3dv(V -> Normal);
  186.             glVertex3dv(V -> Coord);
  187.  
  188.             if (IGGlblDrawPNormal) {
  189.             for (j = 0; j < 3; j++)
  190.                 PNormal[j] += V -> Coord[j];
  191.             NumOfVertices++;
  192.             }
  193.         }
  194.         glEnd();
  195.         }
  196.         else {
  197.         glBegin(GL_LINE_STRIP);
  198.         for (V = Pl -> PVertex; V != NULL; V = V -> Pnext) {
  199.             glVertex3dv(V -> Coord);
  200.             if (IP_IS_INTERNAL_VRTX(V) && !IGGlblDrawInternal) {
  201.             glEnd();
  202.             glBegin(GL_LINE_STRIP);
  203.             }
  204.  
  205.             if (IGGlblDrawPNormal) {
  206.             for (j = 0; j < 3; j++)
  207.                 PNormal[j] += V -> Coord[j];
  208.             NumOfVertices++;
  209.             }
  210.         }
  211.         glVertex3dv(Pl -> PVertex -> Coord);
  212.         glEnd();
  213.         }
  214.  
  215.         if (IGGlblDrawPNormal && IP_HAS_PLANE_POLY(Pl)) {
  216.         glBegin(GL_LINES);
  217.         for (i = 0; i < 3; i++)
  218.             PNormal[i] /= NumOfVertices;
  219.         glVertex3dv(PNormal);
  220.         for (i = 0; i < 3; i++)
  221.             PNormal[i] += Pl -> Plane[i] * IGGlblNormalLen;
  222.         glVertex3dv(PNormal);
  223.         glEnd();
  224.         }
  225.  
  226.         if (IGGlblDrawVNormal) {
  227.         for (V = Pl -> PVertex; V != NULL; V = V -> Pnext) {
  228.             if (IP_HAS_NORMAL_VRTX(V)) {
  229.             for (j = 0; j < 3; j++)
  230.                 VNormal[j] = V -> Coord[j] +
  231.                          V -> Normal[j] * IGGlblNormalLen;
  232.             glBegin(GL_LINES);
  233.             glVertex3dv(V ->Coord);
  234.             glVertex3dv(VNormal);
  235.             glEnd();
  236.             }
  237.         }
  238.         }
  239.     }
  240.     }
  241. }
  242.  
  243. /*****************************************************************************
  244. * DESCRIPTION:                                                               M
  245. * Sets the color of an object according to its color/rgb attributes.         M
  246. *   If object has an RGB attribute it will be used. Otherwise, if the object M
  247. * has a COLOR attribute it will use. Otherwise, WHITE will be used.         M
  248. *                                                                            *
  249. * PARAMETERS:                                                                M
  250. *   PObj:      To set the drawing color to its color.                        M
  251. *                                                                            *
  252. * RETURN VALUE:                                                              M
  253. *   void                                                                     M
  254. *                                                                            *
  255. * KEYWORDS:                                                                  M
  256. *   IGSetColorObj                                                            M
  257. *****************************************************************************/
  258. void IGSetColorObj(IPObjectStruct *PObj)
  259. {
  260.     int c, Color[3];
  261.  
  262.     if (AttrGetObjectRGBColor(PObj, &Color[0], &Color[1], &Color[2])) {
  263.     SetColorRGB(Color);
  264.     }
  265.     else if ((c = AttrGetObjectColor(PObj)) != IP_ATTR_NO_COLOR) {
  266.     SetColorIndex(c);
  267.     }
  268.     else {
  269.     /* Use white as default color: */
  270.     SetColorIndex(IG_IRIT_WHITE);
  271.     }
  272. }
  273.  
  274. /*****************************************************************************
  275. * DESCRIPTION:                                                               M
  276. * Sets the line width to draw the given object, in pixels.             M
  277. *                                                                            *
  278. * PARAMETERS:                                                                M
  279. *   Width:    In pixels of lines to draw with.                               M
  280. *                                                                            *
  281. * RETURN VALUE:                                                              M
  282. *   void                                                                     M
  283. *                                                                            *
  284. * KEYWORDS:                                                                  M
  285. *   IGSetWidthObj                                                            M
  286. *****************************************************************************/
  287. void IGSetWidthObj(int Width)
  288. {
  289.     glLineWidth(Width);
  290. }
  291.  
  292. /*****************************************************************************
  293. * DESCRIPTION:                                                               *
  294. * Sets the color according to the given color index.                     *
  295. *                                                                            *
  296. * PARAMETERS:                                                                *
  297. *   color:     Index of color to use. Must be between 0 and IG_MAX_COLOR.    *
  298. *                                                                            *
  299. * RETURN VALUE:                                                              *
  300. *   void                                                                     *
  301. *****************************************************************************/
  302. static void SetColorIndex(int color)
  303. {
  304.     int Color[3];
  305.  
  306.     if (color < 0 || color > IG_MAX_COLOR)
  307.         color = IG_IRIT_WHITE;
  308.  
  309.     Color[0] = Colors[color][0];
  310.     Color[1] = Colors[color][1];
  311.     Color[2] = Colors[color][2];
  312.  
  313.     SetColorRGB(Color);
  314. }
  315.  
  316. /*****************************************************************************
  317. * DESCRIPTION:                                                               *
  318. * Sets the color according to the given RGB values.                 *
  319. *                                                                            *
  320. * PARAMETERS:                                                                *
  321. *   Color:      An RGB vector of integer values between 0 and 255.           *
  322. *                                                                            *
  323. * RETURN VALUE:                                                              *
  324. *   void                                                                     *
  325. *****************************************************************************/
  326. static void SetColorRGB(int Color[3])
  327. {
  328.     int i;
  329.  
  330.     if (IGGlblDrawSolid) {
  331.     GLfloat MatAmbient[4], MatDiffuse[4], MatSpecular[4];
  332.     static GLfloat
  333.         MatShininess[] = { 15.0 };
  334.  
  335.     for (i = 0; i < 3; i++) {
  336.         MatAmbient[i] = 0.2 * Color[0] / 255.0;
  337.         MatDiffuse[i] = 0.4 * Color[i] / 255.0;
  338.         MatSpecular[i] = Color[i] / 255.0;
  339.     }
  340.     MatAmbient[3] = MatDiffuse[3] = MatSpecular[3] = 1.0;
  341.  
  342.     glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, MatAmbient);
  343.     glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MatDiffuse);
  344.     glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, MatSpecular);
  345.     glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, MatShininess);
  346.     }
  347.     else
  348.     glColor3f(Color[0] / 255.0, Color[1] / 255.0, Color[2] / 255.0);
  349.  
  350.     if (IGGlblDepthCue) {
  351.     GLfloat fogColor[4];
  352.  
  353.     for (i = 0; i < 3; i++)
  354.         fogColor[i] = (float) IGGlblBackGroundColor[i] / 255.0;
  355.     fogColor[3] = (float) 1.0;
  356.  
  357.     glEnable(GL_FOG);
  358.     glFogi(GL_FOG_MODE, GL_LINEAR);
  359.     glHint(GL_FOG_HINT, GL_NICEST);
  360.     glFogf(GL_FOG_START, (float) IGGlblZMinClip);
  361.     glFogf(GL_FOG_END, (float) IGGlblZMaxClip);
  362.     glFogfv(GL_FOG_COLOR, fogColor);
  363.     }
  364.     else
  365.     glDisable(GL_FOG);
  366. }
  367.  
  368. /*****************************************************************************
  369. * DESCRIPTION:                                                               M
  370. * This routine (along with SetEntry) was copied from the GLX examples of SGI M
  371. * under 4DGifts. Why is it so difficult to open a window!?             M
  372. *                                                                            *
  373. * PARAMETERS:                                                                M
  374. *   XDisplay:      Display                                                   M
  375. *   Parent:        Parent window.                                            M
  376. *   x, y:          Location.                                                 M
  377. *   w, h:          Size.                                                     M
  378. *   BorderWidth:   Border width.                                             M
  379. *   Type:          Type of window requested.                                 M
  380. *                                                                            *
  381. * RETURN VALUE:                                                              M
  382. *   Window:        Created window, NULL if failed.                           M
  383. *                                                                            *
  384. * KEYWORDS:                                                                  M
  385. *   GLXCreateWindow                                                          M
  386. *****************************************************************************/
  387. static void SetEntry(GLXconfig* ptr, int b, int m, int a)
  388. {
  389.     ptr->buffer = b;
  390.     ptr->mode = m;
  391.     ptr->arg = a;
  392. }
  393.  
  394. static Window GLXCreateWindow(Display *XDisplay,
  395.                   Window Parent,
  396.                   int x,
  397.                   int y,
  398.                   int w,
  399.                   int h,
  400.                   int BorderWidth,
  401.                   GLXWindowType Type)
  402. {
  403.     GLXconfig params[50];
  404.     GLXconfig *next;
  405.     GLXconfig *retconfig;
  406.     XVisualInfo *vis;
  407.     XVisualInfo template;
  408.     XColor white;
  409.     XSetWindowAttributes cwa;
  410.     XWindowAttributes pwa;
  411.     int i, nret;
  412.     Window win;
  413.     static char
  414.         *TypeToName[] = {
  415.         "color index single buffer",
  416.         "color index double buffer",
  417.         "rgb single buffer",
  418.         "rgb double buffer",
  419.     };
  420.  
  421.     CMap = DefaultColormap(XDisplay, DefaultScreen(XDisplay));
  422.  
  423.     /*
  424.      * This builds an array in "params" that describes for GLXgetconfig(3G)
  425.      * the type of GL drawing that will be done.
  426.      */
  427.     next = params;
  428.     switch (Type) {
  429.     case GLXcolorIndexSingleBuffer:
  430.         SetEntry(next++, GLX_NORMAL, GLX_RGB, FALSE);
  431.         SetEntry(next++, GLX_NORMAL, GLX_DOUBLE, FALSE);
  432.         break;
  433.     case GLXcolorIndexDoubleBuffer:
  434.         SetEntry(next++, GLX_NORMAL, GLX_RGB, FALSE);
  435.         SetEntry(next++, GLX_NORMAL, GLX_DOUBLE, TRUE);
  436.         break;
  437.     case GLXrgbSingleBuffer:
  438.         SetEntry(next++, GLX_NORMAL, GLX_RGB, TRUE);
  439.         SetEntry(next++, GLX_NORMAL, GLX_DOUBLE, FALSE);
  440.         break;
  441.     case GLXrgbDoubleBuffer:
  442.         SetEntry(next++, GLX_NORMAL, GLX_RGB, TRUE);
  443.         SetEntry(next++, GLX_NORMAL, GLX_DOUBLE, TRUE);
  444.         break;
  445.     }
  446.     SetEntry(next, 0, 0, 0); /* The input to GLXgetconfig is null terminated */
  447.  
  448.     /*
  449.      * Get configuration data for a window based on above parameters
  450.      * First we have to find out which screen the parent window is on,
  451.      * then we can call GXLgetconfig()
  452.      */
  453.     XGetWindowAttributes(XDisplay, Parent, &pwa);
  454.     retconfig = GLXgetconfig(XDisplay, XScreenNumberOfScreen(pwa.screen),
  455.                  params);
  456.     if (retconfig == 0) {
  457.     printf("Sorry, can't support %s type of windows\n", TypeToName[Type]);
  458.     exit(-1);
  459.     }
  460.     /*
  461.      * The GL sets its own X error handlers, which aren't as informative
  462.      * when errors happen.  Calling XSetErrorHandler(0) here will
  463.      * reset back to the default Xlib version.
  464.      */
  465.     XSetErrorHandler(0);
  466.  
  467.     /*
  468.      * Scan through config info, pulling info needed to create a window
  469.      * that supports the rendering mode.
  470.      */
  471.     for (next = retconfig; next->buffer; next++) {
  472.     unsigned long buffer = next->buffer;
  473.     unsigned long mode = next->mode;
  474.     unsigned long value = next->arg;
  475.     switch (mode) {
  476.       case GLX_COLORMAP:
  477.         if (buffer == GLX_NORMAL) {
  478.         CMap = value;
  479.         }
  480.         break;
  481.       case GLX_VISUAL:
  482.         if (buffer == GLX_NORMAL) {
  483.         template.visualid = value;
  484.         template.screen = DefaultScreen(XDisplay);
  485.         vis = XGetVisualInfo(XDisplay, VisualScreenMask | VisualIDMask,
  486.                      &template, &nret);
  487.         }
  488.         break;
  489.     }
  490.     }
  491.  
  492.     /*
  493.      * Create the window
  494.      */
  495.     cwa.colormap = CMap;
  496.     cwa.border_pixel = 0;  /* Even if we don't use it, it must be something */
  497.     win = XCreateWindow(XDisplay, Parent, x, y, w, h,
  498.             BorderWidth, vis->depth, InputOutput, vis->visual,
  499.             CWColormap|CWBorderPixel, &cwa);
  500.  
  501.     /*
  502.      * Rescan configuration info and find window slot that getconfig
  503.      * provided.  Fill it in with the window we just created.
  504.      */
  505.     for (next = retconfig; next->buffer; next++) {
  506.     if ((next->buffer == GLX_NORMAL) && (next->mode == GLX_WINDOW)) {
  507.         next->arg = win;
  508.         break;
  509.     }
  510.     }
  511.  
  512.     /*
  513.      * Now "retconfig" contains all the information the GL needs to
  514.      * configure the window and its own internal state.
  515.      */
  516.     i = GLXlink(XDisplay, retconfig);
  517.     if (i < 0) {
  518.     printf("GLXlink returned %d\n", i);
  519.     exit(-1);
  520.     }
  521.  
  522.     return win;
  523. }
  524.  
  525. /*****************************************************************************
  526. * DESCRIPTION:                                                               M
  527. * Sets up a view window.                             M
  528. *                                                                            *
  529. * PARAMETERS:                                                                M
  530. *   argc, argv:   Command line,                                              M
  531. *                                                                            *
  532. * RETURN VALUE:                                                              M
  533. *   void                                                                     M
  534. *                                                                            *
  535. * KEYWORDS:                                                                  M
  536. *   SetViewWindow                                                            M
  537. *****************************************************************************/
  538. void SetViewWindow(int argc, char **argv)
  539. {
  540.     static int
  541.     UpdateLightPos = FALSE;
  542.     static GLfloat
  543.     Light0Position[4] = { 1.0, 2.0, 10.0, 0.0 },
  544.     Light1Position[4] = { -5.0, -1.0, -10.0, 0.0 },
  545.     LightAmbient[] = { 1.0, 1.0, 1.0, 1.0 },
  546.     LightDiffuse[] = { 1.0, 1.0, 1.0, 1.0 },
  547.     LightSpecular[] = { 1.0, 1.0, 1.0, 1.0 },
  548.     LModelAmbient[] = { 0.2, 0.2, 0.2, 1.0 };
  549.     Cursor XCursor;
  550.  
  551.     ViewWndw = GLXCreateWindow(XDisplay, XRoot,
  552.                    ViewPosX, ViewPosY,
  553.                    ViewWidth, ViewHeight,
  554.                    0, GLXrgbDoubleBuffer);
  555.  
  556.     /* Set our own cursor: */
  557.     XCursor = XCreateFontCursor(XDisplay, XC_iron_cross);
  558.     XDefineCursor(XDisplay, ViewWndw, XCursor);
  559.     if (ViewCursorColor != NULL)
  560.     XRecolorCursor(XDisplay, XCursor, ViewCursorColor, &BlackColor);
  561.  
  562.     XSelectInput(XDisplay, ViewWndw, ExposureMask | ButtonPressMask);
  563.     
  564.     XMapWindow(XDisplay, ViewWndw);
  565.  
  566.     if (!UpdateLightPos) {
  567.     int i;
  568.     
  569.     for (i = 0; i < 4; i++)
  570.         Light0Position[i] = IGGlblLightSrcPos[i];
  571.     UpdateLightPos = TRUE;
  572.     }
  573.  
  574.     glXMakeCurrent(XDisplay, None, NULL);
  575.  
  576.     glLightfv(GL_LIGHT0, GL_POSITION, Light0Position);
  577.     glLightfv(GL_LIGHT0, GL_AMBIENT, LightAmbient);
  578.     glLightfv(GL_LIGHT0, GL_DIFFUSE, LightDiffuse);
  579.     glLightfv(GL_LIGHT0, GL_SPECULAR, LightSpecular);
  580.     glLightfv(GL_LIGHT1, GL_POSITION, Light1Position);
  581.     glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient);
  582.     glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse);
  583.     glLightfv(GL_LIGHT1, GL_SPECULAR, LightSpecular);
  584.     glLightModelfv(GL_LIGHT_MODEL_AMBIENT, LModelAmbient);
  585.  
  586.     glDepthFunc(GL_GREATER);
  587.     glClearDepth(0.0);
  588. }
  589.  
  590. /*****************************************************************************
  591. * DESCRIPTION:                                                               *
  592. * Redraw the view window.                                                    *
  593. *                                                                            *
  594. * PARAMETERS:                                                                *
  595. *   None                                                                     *
  596. *                                                                            *
  597. * RETURN VALUE:                                                              *
  598. *   void                                                                     *
  599. *****************************************************************************/
  600. void RedrawViewWindow(void)
  601. {
  602.     IPObjectStruct *PObj;
  603.     GLdouble CrntView[16];
  604.     int i, j, k;
  605.  
  606.     glDrawBuffer(IGGlblDoDoubleBuffer ? GL_BACK : GL_FRONT);
  607.  
  608.     /* Clear viewing area. */
  609.     glClear(GL_COLOR_BUFFER_BIT |
  610.         (IGGlblDrawSolid ? GL_DEPTH_BUFFER_BIT : 0));
  611.  
  612.     /* activate zbuffer only if we are in solid drawing mode. */
  613.     if (IGGlblDrawSolid) {
  614.     glEnable(GL_LIGHTING);
  615.     glEnable(GL_LIGHT0);
  616.     glEnable(GL_LIGHT1);
  617.     glEnable(GL_DEPTH_TEST);
  618.     glDisable(GL_CULL_FACE);
  619.     glClear(GL_DEPTH_BUFFER_BIT);
  620.     }
  621.     else {
  622.     glDisable(GL_LIGHTING);
  623.     glDisable(GL_LIGHT0);
  624.     glDisable(GL_LIGHT1);
  625.     glDisable(GL_DEPTH_TEST);
  626.     }
  627.  
  628.     if (IGGlblViewMode == IG_VIEW_PERSPECTIVE) {
  629.     for (i = 0; i < 4; i++)
  630.         for (j = 0; j < 4; j++) {
  631.         CrntView[i * 4 + j] = 0;
  632.         for (k = 0; k < 4; k++)
  633.             CrntView[i * 4 + j] += IritPrsrViewMat[i][k] *
  634.                                IritPrsrPrspMat[k][j];
  635.         }
  636.     }
  637.     else {
  638.     for (i = 0; i < 4; i++)
  639.         for (j = 0; j < 4; j++)
  640.         CrntView[i * 4 + j] = IritPrsrViewMat[i][j];
  641.     }
  642.  
  643.     glLoadMatrixd(CrntView);
  644.     glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
  645.  
  646.     for (PObj = IGGlblDisplayList; PObj != NULL; PObj = PObj -> Pnext)
  647.     IGDrawObject(PObj);
  648.     glFlush();
  649.  
  650.     if (IGGlblDoDoubleBuffer)
  651.     glXSwapBuffers(XDisplay, ViewWndw);
  652. }
  653.  
  654. /*****************************************************************************
  655. * DESCRIPTION:                                                               M
  656. * To handle internal events. Should not block.                               M
  657. *                                                                            *
  658. * PARAMETERS:                                                                M
  659. *   None                                                                     M
  660. *                                                                            *
  661. * RETURN VALUE:                                                              M
  662. *   void                                                                     M
  663. *****************************************************************************/
  664. void IGHandleInternalEvents(void)
  665. {
  666. }
  667.